﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
  <head>
    <link rel="stylesheet" href="${ctx}/common/common.css" />
    <title>Title</title>

    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all" />
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all" />
    <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>

    <script src="${ctx}/common/plugins/publicJs/publicJs.js"></script>
    <style>
      .layui-body {
        overflow-y: scroll;
      }
      .laytable-cell-1-turl {
        height: 80px;
        line-height: 80px;
      }
    </style>
  </head>
  <body>
    <!--主体内容层-->
    <div class="layui-fluid">
      <!--通用按钮盒子-->
      <div class="layui-col-md12" style="padding-top: 10px; padding-bottom: 10px">
        <div style="float: right" class="layui-btn-group paramBtn">
          <button data-type="backLabel" type="button" class="layui-btn layui-btn-primary">返回</button>
        </div>
      </div>
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12 layui-col-space15">
          <table
            class="layui-table"
            id="labelReload"
            lay-data="{ url:'${ctx}/label/labelCheckPage1?labelId=${labelId }', page:true,groups:5}"
            lay-filter="demo"
          >
            <thead>
              <tr>
                <th lay-data="{field:'code',height:100,sort:true}">标签码</th>
                <th lay-data="{field:'label_stat',height:100,toolbar:'#stat'}">标签状态</th>
                <th lay-data="{field:'trace_type',height:100,toolbar:'#type'}">溯源类型</th>
                <!--    <th lay-data="{field:'turl',height:100,toolbar:'#img'}">二维码</th> -->
              </tr>
            </thead>
          </table>
        </div>
      </div>
    </div>
    <!--  -->
    <script type="text/html" id="img">
      <img style="width: 80px;height: 80px;" src="${ctx}{{d.turl}}" class="layui-upload-img" />
    </script>

    <script type="text/html" id="type">
      {{# if(d.trace_type == 1){ }} 个体溯源 {{# } }} {{# if(d.trace_type == 2){ }} 批量溯源 {{# } }}
    </script>
    <script id="stat" type="text/html">
      {{# if(d.label_stat == 0){ }} 正常 {{# } }} {{# if(d.label_stat == 1){ }} 作废 {{# } }} {{# if(d.label_stat == 2){
      }} 冻结 {{# } }} {{# if(d.label_stat == 3){ }} 召回 {{# } }}
    </script>
  </body>
  <script>
    layui.use("table", function () {
      var loading = layer.msg("数据加载中...");
      var table = layui.table;
      table.render({
        done: function () {
          layer.close(loading);
        },
      });
      //监听filter为demo的table中的工具条
      table.on("tool(demo)", function (obj) {
        var data = obj.data;
        if (obj.event === "edit") {
          window.location.href = "${ctx}/label/labelEditPage?labelId=" + obj.data.id;
        }
        if (obj.event === "check") {
          window.location.href = "${ctx}/label/labelCheckPage?labelId=" + obj.data.id;
        }
      });

      var $ = layui.$,
        active = {
          reloadLabel: function () {
            //条件查询
            var code = document.getElementById("code").value;
            var creatorName = document.getElementById("creatorName").value;
            var stat = document.getElementById("stat").value;
            table.reload("labelReload", {
              where: {
                code: code,
                creatorName: creatorName,
                stat: stat,
              },
            });
          },
          backLabel: function () {
            window.history.back();
          },
          addPerson: function () {
            window.location.href = "${ctx}/person/personEditPage";
          },
          delPersonSelect: function () {
            var checkStatus = table.checkStatus("labelReload");
            var ids = "";
            var data = checkStatus.data;
            for (var i in data) {
              ids += data[i].id + ",";
            }
            $.post(
              "${ctx}/person/delPersons",
              { personIds: ids },
              function (data) {
                if (data == "success") {
                  layer.alert("删除成功");
                  table.reload("labelReload", {
                    where: {
                      personName: "",
                      deptName: "",
                      companyName: "",
                    },
                  });
                } else {
                  layer.alert("删除失败");
                }
              },
              "text"
            );
          },
        };

      $(".demoTable .layui-btn").on("click", function () {
        var type = $(this).data("type");
        active[type] ? active[type].call(this) : "";
      });
      //给按钮绑定active中的方法
      $(".paramBtn .layui-btn").on("click", function () {
        var type = $(this).data("type");
        //查看是active这个json中是否有type这个方法，如果有调用，如果没有不知心；
        active[type] ? active[type].call() : "";
      });
    });
  </script>
</html>
